from collections import deque
direct = [[-1, 0], [0, -1], [1, 0], [0, 1]]
area = 0

def bfs(grid, visited, x, y):
    queue = deque()
    queue.append([x, y])
    global area
    while queue:
        cur_x, cur_y = queue.popleft()
        
        for i,j in direct:
            next_x = cur_x+i
            next_y = cur_y+j
            if next_x < 0 or next_x >= len(grid[0]) or next_y<0 or next_y>=len(grid):
                continue
        
            if grid[next_y][next_x] == 1 and not visited[next_y][next_x]:
                area += 1
                visited[next_y][next_x] = True
                queue.append([next_x, next_y])

def main():
    row, col = map(int, input().split())
    
    grid = []
    for i in range(row):
        grid.append(list(map(int, input().split())))
    
    visited = [[False]*col for _ in range(row)]
    
    global area
    max_area = 0
    
    for i in range(row):
        for j in range(col):
            if grid[i][j] == 1 and not visited[i][j]:
                area = 1
                visited[i][j] = True
                bfs(grid, visited, j, i)
                max_area = max(area, max_area)
    print(max_area)
        

if __name__ == "__main__":
    main()